﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using Common;

namespace Controller
{
   public  class TableSelectorBO
    {
        private TableSelectorDAO _tsDAO;
        public TableSelectorDAO TsDAO
        {
            get 
            {
                if (_tsDAO == null)
                    _tsDAO = FactoryModelDAO.CurrentFA.CreateTableSelectorDAOInstance();
                
                return _tsDAO; 
            }
        }


        /// <summary>
        /// 保存用于生成控件的信息
        /// </summary>
        /// <param name="xmlPath">需要保存到的路径</param>
        /// <param name="ConfigName">服务器连接信息配置名</param>
        /// <param name="fInfo">生成信息的实体类</param>
        /// <returns>0代表成功，1代表已经存在相同配置</returns>
        public int SaveBuildInfoToXml(string ConfigName, List<exFieldInfo> XmlInfoList)
        {
            return ServerExplorerDAO.SaveBuildInfoToXml(PubConstant.ConfigPath, PubConstant.ServerBuildConfigName, ConfigName, XmlInfoList);
        }



        /// <summary>
        /// 保存服务器连接等设置到配置文件
        /// </summary>
        /// <param name="xmlPath">要保存到的路径</param>
        /// <param name="menuConfig">配置信息实体类</param>
        /// <returns>0代表成功，1代表已经存在相同配置</returns>
        public int SaveMenuConfigToXml(exMenuConfigChild menuConfig)
        {

             return ServerExplorerDAO.SaveMenuConfigToXml(PubConstant.ConfigPath, PubConstant.ServerMenuConfigName, menuConfig);

        }


       /// <summary>
       /// 获取一个表所有的字段信息
       /// </summary>
       /// <param name="conStr">连接字符串</param>
       /// <param name="sqlStr">SQL命令</param>
       /// <param name="tableName">表名</param>
       /// <returns></returns>
        public List<eBuildFieldInfo> GetFieldsByTableFromDb(string conStr, string sqlStr, string tableName) 
        {
            try
            {
                return TsDAO.GetFieldsByTableFromDb(conStr, sqlStr, tableName);
            }
            catch (Exception ex)
            { 
                throw ex; 
            }
        }
    }
}
